package com.solution.admin.order.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.solution.admin.company.dao.CompanyInvoiceDao;
import com.solution.admin.company.entity.CompanyInvoiceEntity;
import com.solution.admin.order.dao.OrderInvoiceDao;
import com.solution.admin.order.entity.OrderInvoiceEntity;
import com.solution.admin.order.service.OrderInvoiceService;
import com.solution.common.dao.BaseDao;
import com.solution.common.page.PageBean;
import com.solution.common.page.PageParam;
import com.solution.common.service.impl.BaseServiceImpl;
import com.sun.org.apache.bcel.internal.generic.LSTORE;

/**
 * 订单发票信息service实现层
 * @author lilp
 * @date 2017-09-18 19:24:52
 */
@Service
public class OrderInvoiceServiceImpl extends BaseServiceImpl<OrderInvoiceEntity> implements OrderInvoiceService {

	/**
	 * 订单发票信息接口
	 */
	@Autowired
	private OrderInvoiceDao orderInvoiceDao;
	
	@Autowired
	private CompanyInvoiceDao companyInvoiceDao;

	protected BaseDao<OrderInvoiceEntity> getDao() {
		return this.orderInvoiceDao;
	}
	
	/**
	 * 获取客户最新的开票信息
	 * @param customerId 客户Id
	 * @return
	 * @author: solin
	 * @date: 2018年1月25日 下午9:33:32
	 */
	@Override
	public OrderInvoiceEntity getLatestByCustomerId(Long customerId) {
		// 最询客户最近一次开票信息
		CompanyInvoiceEntity  lastInvoice = companyInvoiceDao.getLastInvoice(customerId);
		OrderInvoiceEntity invoice = new OrderInvoiceEntity();
		if(lastInvoice != null){
			invoice.setInvoiceType(lastInvoice.getInvoiceType());
			invoice.setCompnayName(lastInvoice.getCompanyName());
			invoice.setTaxNo(lastInvoice.getTaxNo());
			invoice.setRegisteAddress(lastInvoice.getRegisteAddress());
			invoice.setRegistePhone(lastInvoice.getRegistePhone());
			invoice.setBankAccount(lastInvoice.getBankAccount());
			invoice.setOpenBankName(lastInvoice.getOpenBankName());
		}
		return invoice;
	}

	/**
	 * 保存订单发票信息
	 * @param orderInvoiceEntity 订单发票信息实体
	 * @return Long 添加成功订单发票信息的ID
	 * @author lilp
	 * @date 2017-09-18 19:24:52
	 */
	public long saveOrderInvoice(OrderInvoiceEntity orderInvoiceEntity) {
		return orderInvoiceDao.saveOrderInvoice(orderInvoiceEntity);
	}

	/**
	 * 分页查询订单发票信息
	 * @param pageParam 分页参数
	 * @param paramMap 查询参数
	 * @return PageBean 分页参数和分页数据
	 * @author lilp
	 * @date 2017-09-18 19:24:52
	 */
	@Override
	public PageBean listOrderInvoicePage(PageParam pageParam, Map<String, Object> paramMap) {
		return orderInvoiceDao.listOrderInvoicePage(pageParam, paramMap);
	}
	
	/**
	 * 根据ID查询用户信息
	 * @param id 用户id
	 * @return orderInvoiceEntity 用户对象
	 * @author lilp
	 * @date 2017-09-18 19:24:52
	 */
	public OrderInvoiceEntity getOrderInvoiceById(Long id) {
		return orderInvoiceDao.getById(id.longValue());
	}

	/**
	 * 更新用户
	 * @param orderInvoiceEntity 用户实体
	 * @return Long 更新是否成功，>1代表更新成功
	 * @author lilp
	 * @date 2017-09-18 19:24:52
	 */
	@Override
	public int updateOrderInvoice(OrderInvoiceEntity orderInvoiceEntity) {
		return orderInvoiceDao.updateOrderInvoice(orderInvoiceEntity);
	}
	
	
	/**
	 * 根据条件查询订单发票信息
	 * @param param
	 * @return 数据列表
	 * @author lilp
	 * @date 2017-09-18 19:24:52
	 */
	@Override
	public List<OrderInvoiceEntity> listOrderInvoice( Map<String, Object> param){
		return  orderInvoiceDao.listOrderInvoice(param);
	}
	
	/**
	 * 删除订单发票信息
	 * @param 
	 * @return int 返回删除记录条数
	 * @author lilp
	 * @date 2017-09-18 19:24:52
	 */
	public int deleteOrderInvoiceById(long id){
		return  orderInvoiceDao.deleteById(id);
	}
	
}
